﻿@model CategoryModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    Html.AddTitleParts(!String.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    Html.AddMetaDescriptionParts(Model.MetaDescription);
    Html.AddMetaKeywordParts(Model.MetaKeywords);

    var canonicalUrlsEnabled = EngineContext.Current.Resolve<SeoSettings>().CanonicalUrlsEnabled;
    if (canonicalUrlsEnabled)
    {
        var categoryUrl = Url.RouteUrl("Category", new { SeName = Model.SeName }, this.Request.Url.Scheme);
        Html.AddCanonicalUrlParts(categoryUrl);
    }

    int currentCategoryId = Convert.ToInt32(Url.RequestContext.RouteData.Values["categoryId"].ToString());
    int currentStoreId = Nop.Core.Domain.Stores.Store.AllStoreReservedId;
    if( Url.RequestContext.RouteData.Values.ContainsKey("storeId") )
    {
        currentStoreId = Convert.ToInt32(Url.RequestContext.RouteData.Values["storeId"].ToString());
    }
}
@using Nop.Core;
@using Nop.Core.Domain.Common;
@using Nop.Core.Domain.Seo;
@using Nop.Core.Infrastructure;
@using Nop.Web;
@using Nop.Web.Models.Catalog;
@using Nop.Web.Extensions;
@*category breadcrumb*@
@if (Model.DisplayCategoryBreadcrumb)
{


    @Html.Widget("categorydetails_after_breadcrumb")
}
<div class="page category-page">

    <div class="page-title">
        
        @*
        @if (Model.SubCategories.Count <= 0)
        {
            <img alt="@Model.PictureModel.AlternateText" src="@Model.PictureModel.ImageUrl" title="@Model.Name" />
        }
        *@
    </div>
    
    <div class="page-body">
        @Html.Widget("categorydetails_top")
        @*description*@
        @if (!String.IsNullOrWhiteSpace(Model.Description))
        {
            <div class="category-description">
                @Html.Raw(Model.Description)
            </div>
            <div class="clear">
            </div>
        }
        @Html.Widget("categorydetails_before_subcategories")

        @*subcategories
        @if (Model.SubCategories.Count > 0)
        {
            <div class="sub-category-grid">
                @(Html.UnorderedList<CategoryModel.SubCategoryModel>(Model.SubCategories, 3,
                @<div class="item-box">
                    <div class="sub-category-item">
                        <div class="picture">
                            @if( currentStoreId > 1 )
                            {
                                <a href="@Url.RouteUrl("PerStoreCategory", new { SeName = item.SeName, categoryId = item.Id, storeId = currentStoreId })" title="@item.PictureModel.Title">
                                    <img alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl"
                                        title="@item.PictureModel.Title" /></a>
                            }
                            else
                            {
                                <a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
                                    <img alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl"
                                        title="@item.PictureModel.Title" /></a>
                            }
                        </div>
                    </div>
                </div>
            ))
            </div>

        } *@

        @Html.Widget("categorydetails_before_featured_products")
        @*featured products*@
        @if (Model.FeaturedProducts.Count > 0)
        {
            <div class="window product-grid featured-product-grid">
                <div class="window-title grad-lightgrey grad">
                    <div class="window-title-bar  grad-titleshine grad">
                        <h2 class="section-title">
                           @T("Products.FeaturedProducts")
                        </h2>
                        <div class="window-title-links hide">
                            <a class="button-grey" href="/Commerce/Catalog/StoreAll">Featured Products</a>

                        </div>
                    </div>
                </div>
                <div class="window-content">
                    @(Html.DataList<ProductOverviewModel>(Model.FeaturedProducts, 2,
                    @<div class="item-box">
                        @Html.Partial("_CustomProductBox", item)
                    </div>
                ))
                </div>
            </div>
            <div class="clear">
            </div>
        }
        @Html.Widget("categorydetails_after_featured_products")
        @*view mode*@
        @*if (Model.PagingFilteringContext.AllowProductViewModeChanging && Model.Products.Count > 0)
        {
            <div class="product-viewmode">
                <span>@T("Categories.ViewMode")</span>
                @Html.DropDownList("products-viewmode", Model.PagingFilteringContext.AvailableViewModes, new { onchange = "setLocation(this.value);" })
            </div>
        }*@

        @*page size*@
        @*if (Model.PagingFilteringContext.AllowCustomersToSelectPageSize && Model.Products.Count > 0)
        {
            <div class="product-page-size">
                <span>@T("Categories.PageSize")</span> <span>@Html.DropDownList("products-pagesize", Model.PagingFilteringContext.PageSizeOptions, new { onchange = "setLocation(this.value);" })</span>
                <span>@T("Categories.PageSize.PerPage")</span>
            </div>
        }
        <div class="clear">
        </div>
        @Html.Widget("categorydetails_before_filters")*@
        @*filtering*@
        @*if (Model.PagingFilteringContext.PriceRangeFilter.Enabled ||
        Model.PagingFilteringContext.SpecificationFilter.Enabled)
        {
            <div class="product-filters">
                <div class="filter-title">
                    <span>@T("Filtering.FilterResults")</span>
                </div>
                @if (Model.PagingFilteringContext.PriceRangeFilter.Enabled)
                {
                    <div class="filter-item">
                        @Html.Partial("_FilterPriceBox", Model.PagingFilteringContext.PriceRangeFilter, new ViewDataDictionary())
                    </div>
                }
                @if (Model.PagingFilteringContext.SpecificationFilter.Enabled)
                {
                    <div class="filter-item">
                        @Html.Partial("_FilterSpecsBox", Model.PagingFilteringContext.SpecificationFilter, new ViewDataDictionary())
                    </div>
                }
            </div>
            <div class="clear">
            </div>
        }*@
        @Html.Widget("categorydetails_before_product_list")
        @*product list*@
        @if (Model.Products.Count > 0)
        {
            if (Model.PagingFilteringContext.ViewMode == "list")
            {
            @*list mode*@
            <div class="product-list">
                @foreach (var product in Model.Products)
                {
                    <div class="item-box">
                        @Html.Partial("_CustomProductBox", product)
                    </div>
                }
            </div>       
            }
            else
            {
            @*grid mode*@
            <div class="product-grid">
                <div class="window">
                    <div class="window-title grad-lightgrey grad">
                        <div class="window-title-bar  grad-titleshine grad">
                            <h2 class="section-title">
                                @Model.Name @*T("Products.FeaturedProducts")*@
                            </h2>
                            <div class="window-title-links">
                                    <div class="product-sorting-wrapper">
                                        @*sorting*@
                                        @if (Model.PagingFilteringContext.AllowProductSorting && Model.Products.Count > 0)
                                        {
                                            <div class="product-sorting">
                                                <table>
                                                    <tbody>
                                                        <tr>
                                                            <td>
                                                                <span class="sort-text">@T("Categories.OrderBy")</span>
                                                            </td>
                                                            <td>
                                                                @Html.DropDownList("products-orderby", Model.PagingFilteringContext.AvailableSortOptions, new { onchange = "setLocation(this.value);" })
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        }
                                    </div>
                            </div>
                        </div>
                    </div>
                    <div class="window-content">
                            <div class="breadcrumb window-content space">
                                <ul>
                                    <li><a href="@Url.RouteUrl("HomePage")" title="@T("Categories.Breadcrumb.Top")">@T("Categories.Breadcrumb.Top")</a>
                                        <span class="delimiter">/</span> </li>
                                    @for (int i = 0; i < Model.CategoryBreadcrumb.Count; i++)
                                    {
                                        var cat = Model.CategoryBreadcrumb[i];
                                        var isLastCategory = cat.Id == Model.Id;
                                        <li>
                                            @if (isLastCategory)
                                            {
                                                @*uncomment to disable clickable link
                                                <strong>@cat.Name</strong>*@
                                                <strong>
                                                    @if( currentStoreId > 1 )
                                                    {
                                                        <a href="@Url.RouteUrl("PerStoreCategory", new { SeName = cat.SeName, categoryId = cat.Id, storeId = currentStoreId })" title="@cat.Name">@cat.Name</a>
                                
                                                    }
                                                    else
                                                    {
                                                        <a href="@Url.RouteUrl("Category", new { SeName = cat.SeName })" title="@cat.Name">@cat.Name</a>
                                                    }
                                                </strong>
                                            }
                                            else
                                            {
                                                if (currentStoreId > 1)
                                                {
                                                    <a href="@Url.RouteUrl("PerStoreCategory", new { SeName = cat.SeName, categoryId = cat.Id, storeId = currentStoreId })" title="@cat.Name">@cat.Name</a>
                                                }
                                                else
                                                {
                                                    <a href="@Url.RouteUrl("Category", new { SeName = cat.SeName })" title="@cat.Name">@cat.Name</a>
                                                }
                                                <span class="delimiter">/</span>
                                            }
                                        </li>
                                    }
                                </ul>
                            </div>
                        @(Html.UnorderedList<ProductOverviewModel>(Model.Products, 2,
                                @<div class="panel-small panel">
                                    @Html.Partial("_CustomProductBox", item)
                                </div>
                            ))
                    </div>
                </div>
            </div>
            }
        }

        <div class="pager">
            @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
        </div>
        @Html.Widget("categorydetails_bottom")

        @Html.Action("HomepageBestSellers", "Catalog", new { area = "Commerce", categoryId = currentCategoryId, storeId = currentStoreId })

        @Html.Action("HomepageWeeklyNewProducts", "Catalog", new { area = "Commerce", categoryId = currentCategoryId, storeId = currentStoreId })


    </div>
</div>
